<?php
require_once './include.php';

$username=$_POST['username'];
$password=$_POST['password'];

$PG = new pgsql("gis24.jlu3s.com", "23456", "ccly", "sde", "GIScontest2024");  
$PG->connect(); 
if(!$PG)  
{  
    $db_error = "无法连接到PostGreSQL数据库！";  
    echo $db_error;   
}  
else  
{  
    //echo "成功连接！";  
    $sql="select * from public.user where username='{$username}' and password='{$password}'";
    //var_dump($sql);
    $result = $PG->query($sql);
    //var_dump($result);
    $row = @pg_fetch_array($result); 
    //var_dump($row);
    $r = $PG->affectedRows();
    //echo $r;
    if($r==1){
        $_SESSION['adminId']=$row['uid'];
        $_SESSION['adminPassword']=$row['password'];
        $_SESSION['adminName']=$row['username'];
        //$_SESSION['adminId']=$row['id'];
        $_SESSION['powerId']=$row['power_id'];
        //alertMes("登录成功","index.php");
        $_SESSION['name']=$row['name'];
        if($row['power_id']==1){
            alertMes("登录成功!欢迎您，您的角色为“普通用户”！","home.php?power=");
        }elseif($row['power_id']==0){
            alertMes("登录成功!欢迎您，您的角色为“管理员”！","home.php?power=");
        }elseif($row['power_id']==2){
            alertMes("抱歉，您的用户已被冻结，请联系管理员解冻","login.php?u={$username}&p=");
        }
    }else{
        alertMes("用户名或密码错误，登录失败，请重新登录！","login.php?u={$username}&p=");
    }    
    
}
